import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Table } from 'antd';
import { address_analyse } from "./data";

class TableComponent extends Component {
    analysisReceivingAddress = () => {
        // 一层
        const resAddressAnalyse = address_analyse
        // 4.1 详细地址分析
        const addressAnalysisColumns = [
            {
                title: '名称',
                dataIndex: 'nameTitle',
                key: 'nameTitle',
                width: 225,
                fixed: 'left',
            },
        ]

        const addressAnalysisList = [
            {
                key: 1,
                nameTitle: '收货地址',
            },
            {
                key: 2,
                nameTitle: '收货姓名',
            },
            {
                key: 3,
                nameTitle: '联系电话',
            },
            {
                key: 4,
                nameTitle: '最早一笔订单时间',
            },
            {
                key: 5,
                nameTitle: '最近一笔订单时间',
            },
            {
                key: 6,
                nameTitle: '近30天订单数',
            },
            {
                key: 7,
                nameTitle: '近30天订单占比',
            },
            {
                key: 8,
                nameTitle: '近30天消费金额',
            },
            {
                key: 9,
                nameTitle: '近30天消费金额占比',
            },
            {
                key: 10,
                nameTitle: '近30天单笔消费最大金额',
            }
        ]
        if (resAddressAnalyse && resAddressAnalyse.length > 0) {
            resAddressAnalyse.map((d, i) => {
                const item5 = {
                    title: `地址${i + 1}`,
                    dataIndex: `addressTitle${i + 1}`,
                    render: (text, row, index) => {
                        if (index === 0) {
                            return (
                                <div>
                                    <div>
                                        {
                                            text
                                        }
                                    </div>
                                    <div>
                                        {d.is_self_address === 1 && <div>本人地址</div>}
                                        {d.note === 1 && <div>默认地址</div>}
                                    </div>
                                </div>)
                        } else {
                            return text
                        }
                    }
                }
                addressAnalysisColumns.push(item5)
                addressAnalysisList[0][`addressTitle${i + 1}`] = d.receive_address
                addressAnalysisList[1][`addressTitle${i + 1}`] = d.name
                addressAnalysisList[2][`addressTitle${i + 1}`] = d.mobile
                addressAnalysisList[3][`addressTitle${i + 1}`] = d.first_order_time
                addressAnalysisList[4][`addressTitle${i + 1}`] = d.last_order_time
                addressAnalysisList[5][`addressTitle${i + 1}`] = d.order_quantity_m1
                addressAnalysisList[6][`addressTitle${i + 1}`] = d.order_ratio_m1
                addressAnalysisList[7][`addressTitle${i + 1}`] = d.order_amount_m1
                addressAnalysisList[8][`addressTitle${i + 1}`] = d.order_amount_ratio_m1
                addressAnalysisList[9][`addressTitle${i + 1}`] = d.single_order_max_amount_m1;
                return addressAnalysisColumns
            })
        }
        console.log('addressAnalysisList', addressAnalysisList);
        console.log('addressAnalysisColumns', addressAnalysisColumns);
        return (
            <div>
                <div id="table4">
                    <Table
                        columns={addressAnalysisColumns}
                        dataSource={addressAnalysisList}
                        pagination={false}
                        scroll={{ x: 'max-content' }}
                        showHeader={false}
                    />
                </div>
            </div>
        )
    }
    render() {
        return (
            <div>
                <p>table</p>
                {this.analysisReceivingAddress()}
            </div>
        )
    }

}

export default connect()(TableComponent);